package com.x.provider.oss.controller.rpc;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.introspect.AnnotatedField;
import com.x.core.web.api.R;
import com.x.provider.api.oss.model.dto.map.DistrictDTO;
import com.x.provider.api.oss.model.dto.map.DistrictListRequestDTO;
import com.x.provider.api.oss.service.MapRpcService;
import com.x.provider.oss.service.MapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/rpc/map")
public class MapRpcController implements MapRpcService {

    private final MapService mapService;

    @Autowired
    private ObjectMapper objectMapper;

    public MapRpcController(MapService mapService){
        this.mapService = mapService;
    }

    @PostMapping("/district/list")
    @Override
    public R<List<DistrictDTO>> listDistrict(@RequestBody DistrictListRequestDTO reqDTO)  {
        List<DistrictDTO> result = new ArrayList<>();
        result.add(DistrictDTO.builder().id("1").TestED("333").build());
        try {
            objectMapper.setPropertyNamingStrategy(new PropertyNamingStrategy() {
                @Override
                public String nameForField(MapperConfig<?> config, AnnotatedField field, String defaultName) {
                    return defaultName; // 直接返回字段原名
                }
            });
            String s = objectMapper.writeValueAsString(result);
        }
       catch (Exception e){

       }
        return R.ok(result);
    }
}
